'''
Created on 13/12/2009

@author: Oded
'''
from google.appengine.api import users



def GetConstSplit(content):
    contentsplit = content.split('=')
    return contentsplit

def CheckConstValid(content):    
    #Checks if the user entered a valid term
    if content.find('=') == -1:
        raise ValueError, "invalid constant definition, constant must have equal sign"
    else:
        newname = GetConstSplit(content)[0]
        newvalue = GetConstSplit(content)[1]
    try:
        float(newvalue)
    except ValueError:
        raise ValueError, "invalid constant definition, constant must be a number"        
        
    #check if name already exists in Users DataBase
    from nerd.web.library import Library
    l = Library(users.get_current_user())
    constantlist = l.get_conste()
    for x in constantlist:
        if x.name == newname:
            raise ValueError, "Constant name already exists in DataBase"
